<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


// retreiving amount of closed srs by products for each group

$query = 'select tse.team, 
                     tse.tse_name,  
  year(from_unixtime(srs.closed)) as year,
 month(from_unixtime(srs.closed)) as month, 
               count(srs.sr) as srs
              from tse, srs 
              where tse.owner_id = srs.owner and
                    tse.owner_id in (' . $ids . ') and
                    srs.closed > ' . $from . ' and
                    srs.closed < ' . $till . ' and 
                    srs.owner = tse.owner_id
              group by tse.team, tse.tse_name, year, month 
              order by tse.team, tse.tse_name, year, month;';
@ $result = mysql_query($query);

while (@ $res = mysql_fetch_assoc($result)) {
    $monthly[$res['tse_name']][$res['year']][$res['month']]['Closed'] = $res['srs'];
} //[$res['team']]
@ mysql_free_result($result);

$query = 'select tse.team, 
                     tse.tse_name,  
  year(from_unixtime(srs.closed)) as year,
 month(from_unixtime(srs.closed)) as month, 
               count(srs.sr) as srs
              from tse, srs 
              where tse.owner_id = srs.owner and
                    tse.owner_id in (' . $ids . ') and
                    srs.closed > ' . $from . ' and
                    srs.closed < ' . $till . ' and 
                    srs.owner = tse.owner_id and 
                    tier_t_owner is not NULL
              group by tse.team, tse.tse_name, year, month 
              order by tse.team, tse.tse_name, year, month;';
@ $result = mysql_query($query);

while (@ $res = mysql_fetch_assoc($result)) {
    $monthly[$res['tse_name']][$res['year']][$res['month']]['T3'] = $res['srs'];
}
@ mysql_free_result($result);

$query = 'select tse.team, 
                 tse.tse_name,  
year(from_unixtime(srs.closed)) as year,
month(from_unixtime(srs.closed)) as month, 
           count(distinct srs.sr) as srs
          from tse, srs, kcs 
          where tse.owner_id = srs.owner and
                kcs.sr = srs.sr and
                tse.owner_id in (' . $ids . ') and
                srs.closed > ' . $from . ' and
                srs.closed < ' . $till . ' and 
                srs.owner = tse.owner_id 
          group by tse.team, tse.tse_name, year, month 
          order by tse.team, tse.tse_name, year, month;';

@ $result = mysql_query($query);

while (@ $res = mysql_fetch_assoc($result)) {
    $monthly[$res['tse_name']][$res['year']][$res['month']]['linked'] = $res['srs'];
}
@ mysql_free_result($result);
?>
